/**
 * 
 */
package de.tum.in.eist.poll.client.views.widgets.questions;

import java.util.ArrayList;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.TextBox;

import de.tum.in.eist.poll.shared.beans.SingleChoiceQuestion;

/**
 * @author Sebastian Hofstetter
 *
 */
public class QuestionCreationSingleChoiceWidget extends QuestionCreationWidget{

	private TextBox textBox = new TextBox();
	private ArrayList<TextBox> choices = new ArrayList<TextBox>();
	private Button addButton = new Button("Add Choice");
	
	public QuestionCreationSingleChoiceWidget() {
		textBox.setText("Single-Choice-Question Description");
		textBox.setWidth("400px");
		add(textBox);
		
		addButton.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				TextBox choice = new TextBox();
				choice.setText("Choice");
				add(choice);
				choices.add(choice);
			}
		});
		add(addButton);
		
	}
	/* (non-Javadoc)
	 * @see de.tum.in.eist.poll.client.views.widgets.questions.QuestionCreationWidget#getQuestion()
	 */
	@Override
	public SingleChoiceQuestion getQuestion() {
		String[] cS = new String[choices.size()];
		for (int i = 0; i < choices.size(); i++) {
			cS[i] = choices.get(i).getText();
		}
		return new SingleChoiceQuestion(textBox.getText(),true,cS);
	}

}
